﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace Toolkit.Web.ViewComponents.DataGrid
{
    [DataContract]
    public sealed class ClientDataGridColumnModel<T> where T : class
    {
        public ClientDataGridColumnModel(DataGridColumn<T> column, int visibleIndex, int renderedIndex)
        {
            if (column == null)
            {
                throw new ArgumentNullException("column");
            }

            key = column.Settings.Key;
            width = column.Settings.Width.HasValue ? column.Settings.Width.Value : column.DataGrid.Settings.DefaultColumnWidth;
            this.index = visibleIndex;
            this.renderedIndex = renderedIndex;
            isVisible = column.Settings.IsVisible;
            sortExpressionEncoded = column.Settings.SortExpression.Encoded;
            sortExpressionEncrypted = column.Settings.SortExpression.Encrypted;
            enableMenu = column.Settings.EnableMenu;
            enableResizing = column.Settings.EnableResizing;
            enableSorting = column.Settings.EnableSorting;
            enableHidingAndShowing = column.Settings.EnableHidingAndShowing;
            enableFiltering = column.IsFilterable;
            enableEditing = column.Settings.EnableEditing;
            lockPositionLeft = column.Settings.LockPositionLeft;
        }

        [DataMember]
        public string key
        {
            get;
            private set;
        }

        [DataMember]
        public int width
        {
            get;
            private set;
        }

        [DataMember]
        public int index
        {
            get;
            private set;
        }

        [DataMember]
        public int renderedIndex
        {
            get;
            private set;
        }

        [DataMember]
        public bool isVisible
        {
            get;
            private set;
        }

        [DataMember]
        public string sortExpressionEncoded
        {
            get;
            private set;
        }

        [DataMember]
        public string sortExpressionEncrypted
        {
            get;
            private set;
        }

        [DataMember]
        public bool enableMenu
        {
            get;
            private set;
        }

        [DataMember]
        public bool enableResizing
        {
            get;
            private set;
        }

        [DataMember]
        public bool enableSorting
        {
            get;
            private set;
        }

        [DataMember]
        public bool enableHidingAndShowing
        {
            get;
            private set;
        }

        [DataMember]
        public bool enableFiltering
        {
            get;
            private set;
        }

        [DataMember]
        public bool enableEditing
        {
            get;
            private set;
        }

        [DataMember]
        public bool lockPositionLeft
        {
            get;
            private set;
        }
    }
}
